home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / stab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-04  |  2.8 KB  |  122 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted provided
  7.  * that: (1) source distributions retain this entire copyright notice and
  8.  * comment, and (2) distributions including binaries display the following
  9.  * acknowledgement:  ``This product includes software developed by the
  10.  * University of California, Berkeley and its contributors'' in the
  11.  * documentation or other materials provided with the distribution and in
  12.  * all advertising materials mentioning features or use of this software.
  13.  * Neither the name of the University nor the names of its contributors may
  14.  * be used to endorse or promote products derived from this software without
  15.  * specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  */
  20.  
  21. #ifndef lint
  22. static char sccsid[] = "@(#)stab.c    5.7 (Berkeley) 6/1/90";
  23. static char  rcsid[] = "@(#)$Id: stab.c,v 5.7.0.2 1991/04/05 14:55:15 paul Exp $";
  24. #endif /* not lint */
  25.  
  26. # include "sendmail.h"
  27.  
  28. /*
  29. **  STAB -- manage the symbol table
  30. **
  31. **    Parameters:
  32. **        name -- the name to be looked up or inserted.
  33. **        type -- the type of symbol.
  34. **        op -- what to do:
  35. **            ST_ENTER -- enter the name if not
  36. **                already present.
  37. **            ST_FIND -- find it only.
  38. **
  39. **    Returns:
  40. **        pointer to a STAB entry for this name.
  41. **        NULL if not found and not entered.
  42. **
  43. **    Side Effects:
  44. **        can update the symbol table.
  45. */
  46.  
  47. # define STABSIZE    400
  48.  
  49. static STAB    *SymTab[STABSIZE];
  50.  
  51. STAB *
  52. stab(name, type, op)
  53.     const char *name;
  54.     int type;
  55.     int op;
  56. {
  57.     register STAB *s;
  58.     register STAB **ps;
  59.     register int hfunc;
  60.     register const char *p;
  61.  
  62.     if (tTd(36, 5))
  63.         printf("STAB: %s %d ", name, type);
  64.  
  65.     /*
  66.     **  Compute the hashing function
  67.     **
  68.     **    We could probably do better....
  69.     */
  70.  
  71.     hfunc = type;
  72.     for (p = name; *p != '\0'; p++)
  73.         hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
  74.  
  75.     if (tTd(36, 9))
  76.         printf("(hfunc=%d) ", hfunc);
  77.  
  78.     ps = &SymTab[hfunc];
  79.     while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
  80.         ps = &s->s_next;
  81.  
  82.     /*
  83.     **  Dispose of the entry.
  84.     */
  85.  
  86.     if (s != NULL || op == ST_FIND)
  87.     {
  88.         if (tTd(36, 5))
  89.         {
  90.             if (s == NULL)
  91.                 printf("not found\n");
  92.             else
  93.             {
  94.                 long *lp = (long *) s->s_class;
  95.  
  96.                 printf("type %d val %lx %lx %lx %lx\n",
  97.                     s->s_type, lp[0], lp[1], lp[2], lp[3]);
  98.             }
  99.         }
  100.         return (s);
  101.     }
  102.  
  103.     /*
  104.     **  Make a new entry and link it in.
  105.     */
  106.  
  107.     if (tTd(36, 5))
  108.         printf("entered\n");
  109.  
  110.     /* make new entry */
  111.     s = (STAB *) xalloc(sizeof *s);
  112.     bzero((char *) s, sizeof *s);
  113.     s->s_name = newstr(name);
  114.     makelower(s->s_name);
  115.     s->s_type = type;
  116.  
  117.     /* link it in */
  118.     *ps = s;
  119.  
  120.     return (s);
  121. }
  122.